//
//  ViewController.m
//  类似于点评_评分
//
//  Created by dpfst520 on 16/2/19.
//  Copyright © 2016年 NttData.dang. All rights reserved.
//

#import "ViewController.h"
#import "Grade.h"

@interface ViewController ()<GradeDelegate>

@property (nonnull, strong)UILabel *mLabel;

@property (nonnull, strong)Grade *ratingBar;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self initWithUI];
    
}

#pragma mark -- 初始化view
- (void)initWithUI
{
    CGFloat width = 200;
    CGFloat x = (self.view.bounds.size.width - width) * 0.5;
    self.ratingBar = [[Grade alloc]initWithFrame:CGRectMake(x, 100, width, 50)];
    
    [self.view addSubview:self.ratingBar];
    
    //是否显示指示器
    self.ratingBar.isIndicator = NO;
    
    [self.ratingBar setImageDeselected:@"iconfont-xingunselected" halfSelected:@"iconfont-banxing" fullSelected:@"iconfont-xing" andDelegate:self];
    
    //显示结果的UILabel
    CGFloat labelX = (self.view.bounds.size.width - 400) * 0.5f;
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(labelX, 200, self.view.frame.size.width, 50)];
    label.textAlignment = NSTextAlignmentCenter;
    label.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:label];
    
    self.mLabel = label;
    
    
}

- (void)ratingBar:(Grade *)ratingBar ratingChanged:(float)newRating
{
    if (self.ratingBar == ratingBar) {
        
        self.mLabel.text = [NSString stringWithFormat:@"评分结果为:%.1f",newRating];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
